package com.tstudy.laoshibang.profile;

import com.nostra13.universalimageloader.core.assist.FailReason;
import com.nostra13.universalimageloader.core.assist.ImageLoadingListener;
import com.tstudy.laoshibang.R;
import com.tstudy.laoshibang.base.BaseApplication;
import com.tstudy.laoshibang.base.CONSTANT;
import com.tstudy.laoshibang.base.HttpManager;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;

public class BigHeaderActivity extends Activity {
	
	RelativeLayout mLoadingLayout;
	public static void show(String imageUrl){
		Intent intent = new  Intent(BaseApplication.mCurrentActivity,BigHeaderActivity.class);
		intent.putExtra(CONSTANT.ARGS.URL, imageUrl);
		BaseApplication.mCurrentActivity.startActivity(intent);
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.big_header);
		ImageView image = (ImageView) findViewById(R.id.big_header_image);
		image.getLayoutParams().height = BaseApplication.mScreenWidth;
		mLoadingLayout = (RelativeLayout)findViewById(R.id.big_header_progress);
		if (getIntent() != null) {
			String imageUrl = getIntent().getStringExtra(CONSTANT.ARGS.URL);
			HttpManager.getInstance().loadCommonImage(image,imageUrl,new ImageLoadingListener() {
				@Override
				public void onLoadingStarted(String imageUri, View view) {
					mLoadingLayout.setVisibility(View.VISIBLE);
				}
				
				@Override
				public void onLoadingFailed(String imageUri, View view, FailReason failReason) {
					mLoadingLayout.setVisibility(View.GONE);
				}
				
				@Override
				public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
					mLoadingLayout.setVisibility(View.GONE);
				}
				
				@Override
				public void onLoadingCancelled(String imageUri, View view) {
					mLoadingLayout.setVisibility(View.GONE);
				}
			});
		}
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		finish();
		if (BaseApplication.mHeaderBM != null) {
			BaseApplication.mHeaderBM.recycle();
			BaseApplication.mHeaderBM = null;
		}
		return true;
	}

}
